package com.wiegand.content {
	import com.caurina.transitions.Tweener;
	import com.wiegand.content.IContent;
	import com.wiegand.event.ContentStatusEvent;

	import flash.display.Sprite;

	/**
	 * @author gandy
	 */
	 
	public class AbstractContent extends Sprite implements IContent {
		protected var _container : Sprite;
		protected var _xml : XMLList;
		protected var _name : String;

		public function AbstractContent(xml:XMLList) {
			_xml = xml;	
			_name = _xml.@name;		
			init();
		}
		
		public function init() : void {
			_container = new Sprite();
			_container.alpha = 0;
			addChild(_container);
		}
		
		public function open(delay : Number = 0) : void {
			Tweener.removeTweens(_container);
			Tweener.addTween(_container,{alpha:1,delay:delay,time:1,transition:"linear",onComplete:callOpen});
		}
		
		public function callOpen() : void {
			dispatchEvent( new ContentStatusEvent( ContentStatusEvent.STATE_OPEN, _name ) );
		}
		
		public function close(delay : Number = 0) : void {
			Tweener.removeTweens(_container);
			Tweener.addTween(_container,{alpha:0,delay:delay,time:1,transition:"linear",onComplete:callClosed});
		}
		
		public function callClosed() : void {
			dispatchEvent( new ContentStatusEvent( ContentStatusEvent.STATE_CLOSED, _name ) );
		}
		
		public function destroy() : void {
			Tweener.removeTweens(_container);
			removeChild(_container);
		}
		
		public function resize() : void {
		}
	}
}
